<?
include("session.php");
$role_name = $_SESSION['role_name'];
$id = "";
if(isset($_GET['id'])) {
	$id = $_GET['id'];
}

$upload_file_name = $_SESSION['user_name']."_".date("Ymd_His").".vox";
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../webkit/utils/jquery.js"></script>
<script type="text/javascript" src="../webkit/utils/form.checker.js"></script>
<script type="text/javascript" src="../webkit/datepicker/WdatePicker.js"></script>
<link type="text/css" rel="stylesheet" href="page.css"/> 
<body  bgcolor="#f4f4f4" style="margin:0px;" scroll=no>

<form name=f enctype="multipart/form-data" method=post action='<?echo $_hncc_interface_uri?>/upload_voice_file.jsp' onsubmit="return begin_upload();" target=free> 
<hr size=1>
<table width=100% cellspacing=1 cellpadding=3 id="basic_info_table"> 
	<tr>
        <td align=right nowrap>任务名称</td><td colspan=3><input type='text' id="task_name" class='input' check='not_empty' warning='任务名称不能为空！' style="width:500px;"></td>  
	</tr>
	<tr>
		<td align=right>外呼类型</td><td><select id="call_type" class='input' onchange="change_call_type(this.value)"><option value=1>VOX录音</option><option value=2 selected>TTS转音</option></select></td>
		<td align=right>外呼号码</td><td><select id="callout_number" class='input'></select></td>
	</tr>
	<tr>
		<td align=right>预约时间</td><td><input type="text" class='input' id="appt_time" name="appt_time" onClick="WdatePicker({readOnly:false, skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" value=""></td>
		<td>按键回接</td><td><select id="callback_key"><option value=-1></option><? for($i=1; $i<10; $i++) { echo "<option value=$i>$i</option>"; } ?></select>
		<input type="text" id="callback_tel" class='input' style="width:160px"></td>
	</tr>
	<tr id="call_type_1" style="display:none">
		<td align=right>上传录音</td><td colspan=3>
		<div style="width:500px; height:75px; background:white" style="border:gray 1px solid; padding:10px 0px 2px 10px">
			<input type="file" name="voice_file_input" size=50> <input type="submit" value="上　传" id="btn_upload"><br>
			【说明】：<font color="#555555">请将本地.vox文件改名为[ <font color=blue style='font-size:15px'><?echo $upload_file_name?></font> ]后，再上传!</font><br>
			 <span id="uploading_tips" style="display:none; text-align:center; color:red; width:100%"><hr size=1>
			 <img src="../webkit/dialog/images/progress.gif"> 上传处理中，请稍候...
			 </span>
		</div>
		<iframe name="free" width=1 height=0 onreadystatechange="iframe_on_change(this)"></iframe>
		<input type="hidden" id="voice_file" value="">
		</td>
	</tr>
	<tr id="call_type_2">
		<td align=right>外呼文本</td><td colspan=3><textarea style="width:500px;height:75px" rows=4 id="voice_text"></textarea></td>
	</tr>
	<tr>
		<td align=right>按键注解</td><td colspan=3><textarea style="width:500px;" rows=2 id="select_key_desc"></textarea></td>
	</tr>
	<tr>
		<td align=right>备　　注</td><td colspan=3><textarea style="width:500px;" rows=2 id="task_desc"></textarea></td>
	</tr>
	<tr>
		<td align=right>回调接口</td><td colspan=3><textarea style="width:500px;" rows=2 id="api_url"></textarea></td>
	</tr>
	<input type='hidden' id="id" value="<?echo $_GET['id']?>">
</form>	

<table width=100% cellspacing=1 cellpadding=3>
	<tr>
		<td align=center>
		<hr size=1>
		<input type="button" id="btn_save" class="button" value="保存信息" onclick="save()">　　<input type="button" class="button" value="关闭窗口" onclick="parent.closeDlg()"></td>
	</tr>
</table>

<script type="text/javascript">
	var op = "<?echo $_GET['op']?>";
	var f = document.f;
	function save() { 
		if(FormChecker.doCheck(f)) {
			var params = {};
			var els = f.elements;
			for(var i=0; i<els.length; i++) {
				if(els[i].type == "button" || els[i].type == "submit") continue;
				params[els[i].id] = els[i].value;
			}

			if($("#voice_text").val().length > 100) {
				alert("外呼文本内容长度(含标点符号)不能超过100个字！请修改内容！");
				return false;
			}

			$.post("task_query.php?action="+op, params, function(data) {
				if(data.indexOf("ok") == 0) {
					alert("数据保存成功!");
					parent.refreshGrid();
					parent.closeDlg();
                } else {  
					alert(data);
				}
			});
		}
	}; 

	function change_call_type(v) {
		if(v == 1) {
			$("#call_type_1").show();
			$("#call_type_2").hide();
		} else {
			$("#call_type_1").hide();
			$("#call_type_2").show();
		}
	}

	var upload_file_name = "<?echo $upload_file_name?>";
	function begin_upload() {
		var file_name = f.voice_file_input.value;
		if(file_name == "") {
			alert('请选择本地VOX录音文件！');
			return false;
		}
		var arr = file_name.split("\\");
		var voice_file_name = arr[arr.length-1];
		//alert(voice_file_name)
		if(voice_file_name != upload_file_name) {
			alert('请将本地VOX录音文件改名为['+upload_file_name+']后，再进行上传！');
			return false;
		}
		if(confirm('确认要上传录音文件吗？')) {
			$('#voice_file').val(voice_file_name);
			$('#btn_upload').attr('disabled', true);
			$('#uploading_tips').show();
			return true;
		}
		return false;
	}

	function iframe_on_change(iframe) {
		if (iframe.readyState && iframe.readyState == 'complete') {
			$('#btn_upload').attr('disabled', false);
			$('#uploading_tips').hide();
		}
	}

	function init() {
	<?
	if($_GET['op'] == 'edit') {
	?>
	$.get("task_query.php?action=get&id=<?echo $_GET['id']?>", function(data){
		eval("var row = "+data);
		for(var k in row) {
			$('#'+k).val(row[k]);
		}
		change_call_type(row['call_type'])
	});
	<?
	}
	?>
	}

	$(function() {
		$.get("user_query.php?action=get_by_uid", function(data) {
			//alert(data)
			eval("var row = "+data);
            var arr = row['callout_number'].split(",");
			for(var i=0; i<arr.length; i++){
				f.callout_number.options[i] = new Option(arr[i], arr[i]);
			}
		});
		init();
	});
</script>
</body>
</html>